package pta.test0809.PersonSortable2类;
import java.util.Comparator;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        PersonSortable2[] persons = new PersonSortable2[n];
        for (int i = 0; i < n; i++) {
            String name = scanner.next();
            int age = scanner.nextInt();
            persons[i] = new PersonSortable2(name, age);
        }

        Comparator<PersonSortable2> nameComparator = new NameComparator();
        Arrays.sort(persons, nameComparator);
        System.out.println("NameComparator:sort");
        for (PersonSortable2 person : persons) {
            System.out.println(person.toString());
        }

        Comparator<PersonSortable2> ageComparator = new AgeComparator();
        Arrays.sort(persons, ageComparator);
        System.out.println("AgeComparator:sort");
        for (PersonSortable2 person : persons) {
            System.out.println(person.toString());
        }

        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
    }
}
class PersonSortable2{
    private String name;
    private int age;

    public PersonSortable2(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public String toString() {
        return name+"-"+age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}


class NameComparator implements Comparator<PersonSortable2> {
    public int compare(PersonSortable2 p1, PersonSortable2 p2) {
        return p1.getName().compareTo(p2.getName());
    }
}

class AgeComparator implements Comparator<PersonSortable2> {
    public int compare(PersonSortable2 p1, PersonSortable2 p2) {
        return p1.getAge() - p2.getAge();
    }
}
